package org.kotboot.ctrl

import org.kotboot.annotations.Auth
import org.kotboot.kit.NumKit
import org.kotboot.module.R
import org.kotboot.service.OrderServ
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController
import javax.annotation.Resource

@RestController
@RequestMapping(value = "/order", method = arrayOf(RequestMethod.POST))
@Auth
class OrderCtrl(
        @Resource val orderServ: OrderServ

) : BaseCtrl() {

    @RequestMapping(value = "/{orderid}", method = arrayOf(RequestMethod.DELETE))
    fun delete(@PathVariable orderid: Long?): R<*>? {
        val params = getParams()
        val userid = params.getLongValue("userid")
        val validRes = validDel(orderid, userid)
        return if (validRes.isErr) {
            validRes
        } else null
        //        R delRes = orderServ.deleteOrder(orderid,userid);
    }

    private fun validDel(orderid: Long?, userid: Long): R<*> {
        return if (NumKit.notPositive(orderid)) {
            R.ER("订单ID格式错误")
        } else R.OK()
    }
}